﻿using Newtonsoft.Json;
using SecurityClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Fish = FSLib.Network.Http;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string client_id = "df1d0922cf5d515ad2aeb286bd0ba45e79d2142e54ed2e19b7ee64318592dd1e";
            string redirect_uri = "http://localhost:50453/api/user/Gettoken";
            string client_secret = "c78757ed08145548fa43be5ab15682a7ecb2fdc426a693ffd43bd70dfec4f657";
            
            Sample sample = new Sample { Url = redirect_uri, };
            RequestData request = new RequestData
            {
                grant_type = "authorization_code",
                code = client_id,
                client_id = client_id,
                redirect_uri = redirect_uri,
                client_secret = client_secret,
            };
            string js = JsonConvert.SerializeObject(request);
            FSLib.Network.Http.HttpClient httpClient = new FSLib.Network.Http.HttpClient();
            string url = "https://gitee.com/oauth/token";

            Fish.HttpContext httpContext = httpClient.Create<string>(FSLib.Network.Http.HttpMethod.Post,
                redirect_uri,
                data: JsonConvert.SerializeObject(request),
                contentType: FSLib.Network.Http.ContentType.Json);

            var clientcontextP = httpContext.Send();
            //    IPEndPoint[] endpoints = new IPEndPoint[]
            //{
            //    //new IPEndPoint(IPAddress.Parse("8.8.4.4"), 53),
            //    //new IPEndPoint(IPAddress.Parse("2001:db8::ff00:42:8329"), 81)
            //    new IPEndPoint(IPAddress.Parse("2001:db8::ff00:42:8329"), 81)
            //};

            //    JsonSerializerSettings settings = new JsonSerializerSettings();
            //    settings.Converters.Add(new IPAddressConverter());
            //    settings.Converters.Add(new IPEndPointConverter());
            //    settings.Formatting = Formatting.Indented;

            //    string json = JsonConvert.SerializeObject(endpoints, settings);
            //    Console.WriteLine(json);

            //    IPEndPoint[] endpoints2 =
            //        JsonConvert.DeserializeObject<IPEndPoint[]>(json, settings);

            //    foreach (IPEndPoint ep in endpoints2)
            //    {
            //        Console.WriteLine();
            //        Console.WriteLine("AddressFamily: " + ep.AddressFamily);
            //        Console.WriteLine("Address: " + ep.Address);
            //        Console.WriteLine("Port: " + ep.Port);
            //    }
            Console.Read();
        }
    }
    public class Sample {
        public String Url { set; get; }
    }
}
